import React, { Component } from "react";
import PropTypes from 'prop-types'

export default class MainBanner extends Component {
  render() {
    const {banners, title} = this.props

    const imgEls = []
    banners.forEach((item, index) => {
      if(index<3) {
        imgEls.push(
          <li key={index}>
            <img src={item.url} alt="" />
          </li>  
        )
      }
    })
    return (
      <div>
        <h1>-----MainBanner组件-----</h1>
        <h2>{title}</h2>
        <ul>
          {imgEls}
        </ul>
      </div>
    )
  }
}
MainBanner.propTypes = {
  banners: PropTypes.array.isRequired,
  title: PropTypes.string
}

MainBanner.defaultProps = {
  banners: [],
  title: '轮播图'
}
